<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let nums = [2, 7, 11, 15,3]
    var twoSum = function (nums, target) {
      let obj = new Map()
      for(let i = 0 ; i<nums.length; i++){
        obj[nums[i]] = i
      }
      // target == 9
      console.log(obj);
      for(let i = 0 ; i<nums.length; i++){
        // console.log(v,i,obj[target - nums[i]]);
        if (obj[target - nums[i]]) {
          return [obj[target - nums[i]], i]
        }
      }
    };

    console.log(twoSum(nums, 9))
  </script>
</body>

</html>